#@layout()
#define main()
<div id="mainContent"></div>
#end
#define js()
<script type="text/javascript">
var mainContent=$("#mainContent");
function loadMainContent(){
	$.get("meinv",function(result){
		mainContent.html(result);
		})
}
/**
 * 添加美女
 */
function addMeinv(){
	if(doing){LayerMsgBox.alert("正在执行抓取任务...",5);return false;}
	LayerMsgBox.prompt("添加美女-多个用空格隔开",'',function(index,text){
		var names=$.trim(text);
		if(names){
			LayerMsgBox.loading("执行中...",10000);
			$.post("meinv/save",{names:names},function(data,status){
				LayerMsgBox.closeAll();
				if(data.state=="ok"){
					loadMainContent();
				}else{
					LayerMsgBox.alert(data.msg);
					}
				});
			}else{
				LayerMsgBox.alert("你不告诉我美女的名字，我上哪儿给你抓~",5);
			}
		});
}
$(function(){
	loadMainContent();
})
/**
 * 删除美女
 */
function deleteMeinv(meinvId){
	LayerMsgBox.confirm('确认删除?',function(){
		LayerMsgBox.loading("执行中...",10000);
		  $.getJSON("meinv/del/"+meinvId,function(){
			 		LayerMsgBox.success("删除成功",300,function(){
						$("#meinvbox_"+meinvId).fadeOut(300,function(){
							$(this).remove();
							if($("img").length==0){
								loadMainContent();
								}
						});
				 	});
			  })
		  
		});
}
var doing=false;
//爬虫执行
function start(ele,meinvId){
	LayerMsgBox.confirm("爬虫执行会先清空相册数据，重新抓取新数据，确认开始吗？",function(){
		doing=true;
		LayerMsgBox.loading("开始抓取，请耐心等待...",2000);
		var btn=$(ele);
		var img=$("#meinvbox_"+meinvId).find("img");
		var oldSrc=img.attr("src");
		img.attr("src","assets/img/doing.gif");
		img.addClass("doing");
				btn.attr("disabled","disabled");
				$(".meinvOptBtn button").attr("disabled","disabled");
				$.getJSON("robot/start/"+meinvId,function(res){
					doing=false;
					btn.removeAttr("disabled");
					$(".meinvOptBtn button").removeAttr("disabled");
					img.removeClass("doing");
					if(res.state=="ok"){
						img.attr("src",res.avatar);
						LayerMsgBox.success("抓取完成",1000);
						}else{
							img.attr("src",oldSrc);
							LayerMsgBox.alert(res.msg,5);
							}
					});
		});
}
</script>
#end

